package com.zifeng.feign.fallback;

import com.zifeng.common.R;
import com.zifeng.exception.BizException;
import com.zifeng.exception.ErrorEnum;
import com.zifeng.feign.OrderFeignClient;
import com.zifeng.pojo.Order;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import static com.zifeng.exception.ErrorCodeAndMsg.*;

@Slf4j
@Component
public class OrderFeignClientFallback implements OrderFeignClient {
    @Override
    public R addOrderWithBlock(Order order) {
        log.error("添加订单失败，订单为：{}", order);
        return R.error(ORDER_FEIGN_ADD_FAIL_CODE, ORDER_FEIGN_ADD_FAIL_MSG)
                .put("error", new BizException(ErrorEnum.ORDER_FEIGN_ADD_FAIL));
    }

    @Override
    public R getOrder(Long id) {
        log.error("获取订单失败，订单ID为：{}", id);
        return R.error(ORDER_FEIGN_SELECT_BY_ID_FAIL_CODE, ORDER_FEIGN_SELECT_BY_ID_FAIL_MSG)
                .put("error", new BizException(ErrorEnum.ORDER_FEIGN_SELECT_BY_ID_FAIL));
    }
}
